package com.sixth.controller;

import com.sixth.dao.StaffDao;
import com.sixth.entity.Staff;
import com.sixth.service.StaffService;
import com.sixth.util.CommonResult;
import com.sixth.util.TableLayUi;
import com.sixth.util.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @program: project01
 * @description:
 * @author: 高振杨
 * @create: 2021-12-17 16:41
 **/
@RestController
@RequestMapping("/staff")
public class StaffController {

    @Autowired
    private StaffService staffService;


    @RequestMapping("/listByCondition")
    //按照条件查询，模糊查询
    public TableLayUi listByCondition(int page, int limit,String staffname,Integer staffid,Integer branchid){
        return staffService.findStaffBycondition(page, limit, staffname, staffid, branchid);
    }

    //离职
    @RequestMapping("/updateState")
    public CommonResult updateState(int state, Integer id){
        System.out.println(state);
        return staffService.updateState(state,id);
    }

    //查询是否有相同的工号
    @RequestMapping("/FindStaffid")
    public CommonResult FindStaffid(Integer staffid){
        return staffService.FindStaffid(staffid);
    }

    //验证一个店铺有一个店长
    @RequestMapping("/position")
    public CommonResult position(Integer branchid){
        return staffService.position(branchid);
    }

    //身份证号验证
    @RequestMapping("/getStaffIdcard")
    public CommonResult getStaffIdcard(String idcard){
        return staffService.getStaffIdcard(idcard);
    }

    //手机号验证
    @RequestMapping("/getStaffPhone")
    public CommonResult getStaffPhone(String phone){
        return staffService.getStaffPhone(phone);
    }

    //冻结
    @RequestMapping("/Dongjie")
    public CommonResult staffDongjie(int state,Integer id){
        return staffService.updateStateDongjie(state,id);
    }

    //解冻
    @RequestMapping("/JieDong")
    public CommonResult staffJieDong(int state,Integer id){
        return staffService.updateStateJieDong(state,id);
    }

    //修改
    @RequestMapping("/edit")
    public CommonResult staffedit(String staffname,String address,String phone,Integer id){
        return staffService.updatestaffmsg(staffname,address,phone,id);
    }

    //添加员工
    @RequestMapping("/StaffAdd")
    public CommonResult StaffAdd(Integer staffid, String staffname, String password, String idcard, String address, String phone, Date entrytime, Integer state, Integer roleid, Integer deptid, String url, Integer branchid){
        return staffService.StaffAdd(staffid,staffname,password,idcard,address,phone,entrytime,state,roleid,url,branchid);
    }

    //调职通过
    @RequestMapping("ExPass")
    public CommonResult ExPass(Integer id, Integer newbranchid, Integer newdeptid , Integer staffid) {
        return staffService.ExPass(id, newbranchid, newdeptid, staffid);
    }

    //调职驳回
    @RequestMapping("ExReject")
    public CommonResult ExReject(Integer id) {
        return staffService.ExReject(id);
    }

    //个人信息查全部
    @RequestMapping("getDeptRole")
    public CommonResult getDeptRole() {
        return staffService.getDeptRole();
    }

    //个人信息查全部
    @RequestMapping("updatePassword")
    public CommonResult updatePassword(String password) {
        return staffService.updatePassword(password);
    }

    //退出登录
    @RequestMapping("out")
    public void Out(HttpServletRequest request, HttpServletResponse response) throws Exception{
        request.getSession().invalidate();
        response.sendRedirect(request.getContextPath() + "/login.jsp");
    }


    //店长下拉框
    @RequestMapping("/getStaffs")
    public CommonResult getStaffs() {
        return staffService.getStaffs();
    }


    //填充员工下拉框
    @RequestMapping("/getStaff")
    public List<Map> getStaff() {
        return staffService.getStaff();
    }

}
